package com.gxa.logistics.service.impl;

import com.gxa.logistics.common.base.RespResult;
import com.gxa.logistics.domain.dto.WarehouseDTO;
import com.gxa.logistics.domain.vo.WarehouseVO;
import com.gxa.logistics.mapper.WarehouseMapper;
import com.gxa.logistics.service.WarehouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class WarehouseServiceImpl implements WarehouseService {
    @Autowired
    private WarehouseMapper warehouseMapper;

    public List<WarehouseDTO> selectWarehouse(int page, int limit) {
//        Map<String, Object> map = new HashMap<>();
//        map.put("code", 0);
//        map.put("msg", "查询成功");
//        map.put("count", warehouseMapper.selectCount());    // 动态统计条数
//
        int index = (page - 1) * limit;
//        map.put("data", warehouseMapper.selectWarehouse(index, limit));
//        System.out.println(map);
        return warehouseMapper.selectWarehouse(index, limit);
    }
    public WarehouseDTO selectWarehouseByName(String warehouse_name) {

        return warehouseMapper.selectWarehouseByName(warehouse_name);
    }

    public Map<String, Object> insert(WarehouseDTO warehouseDTO) {
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("msg", "新增成功");
        warehouseMapper.insert(warehouseDTO.getWarehouse_type(), warehouseDTO.getWarehouse_type(), warehouseDTO.getWarehouse_address());
        return map;
    }

    public Map<String, Object> delete(String warehouse_name) {
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("msg", "删除成功");
        warehouseMapper.delete(warehouse_name);
        return map;
    }
    public Map<String, Object> update(WarehouseDTO warehouseDTO) {
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("msg", "更新成功");
        warehouseMapper.update(warehouseDTO);
        return map;
    }
}
